package com.wits.platform.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.wits.platform.common.JsonDateValueProcessor;

import net.sf.json.JsonConfig;
import net.sf.json.util.PropertyFilter;

@MappedSuperclass
public abstract class BaseEntity implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3494500514455775464L;
	
	public BaseEntity(){
		
	}

	/**
	 * 备注
	 */
	protected String remark;
	
	/**
	 * 建档人
	 */
	protected String userCre;
	
	/**
	 * 建档日期
	 */
	protected Date dateCre;
	
	/**
	 * 修改人
	 */
	protected String userUpd;
	
	/**
	 * 修改日期
	 */
	protected Date dateUpd;
	
	@Column(name = "remark",length=500)
	public String getRemark() {
		return remark;
	}




	public void setRemark(String remark) {
		this.remark = remark;
	}



	@Column(name = "user_cre",length=32,updatable=false)
	public String getUserCre() {
		return userCre;
	}


	public void setUserCre(String userCre) {
		this.userCre = userCre;
	}


	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_cre",updatable=false)
	public Date getDateCre() {
		return dateCre;
	}


	public void setDateCre(Date dateCre) {
		this.dateCre = dateCre;
	}


	@Column(name = "user_upd",length=32)
	public String getUserUpd() {
		return userUpd;
	}


	public void setUserUpd(String userUpd) {
		this.userUpd = userUpd;
	}



	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_upd")
	public Date getDateUpd() {
		return dateUpd;
	}


	public void setDateUpd(Date dateUpd) {
		this.dateUpd = dateUpd;
	}
	
	/**
	 * 
	 * @return
	 */
	public abstract String display();
	
	
	private static JsonConfig baseJsonConfig = new JsonConfig();

	@Transient
	public static JsonConfig getBaseJsonConfig() {
		return baseJsonConfig;
	}

	static {
		baseJsonConfig.registerJsonValueProcessor(Date.class , new JsonDateValueProcessor());
		baseJsonConfig.setJsonPropertyFilter(new PropertyFilter() {
			public boolean apply(Object source, String name, Object value) {
				if (value != null) {
					Class clzss=value.getClass();
					if(clzss.isInstance(java.util.Collection.class) || clzss.isInstance(BaseEntity.class)){
						return true;
					}
				}
				return false;
			}
		});
	}
}
